package com.sip.stream.gbstack;

import com.gosuncn.gbstack.JniGS28181Agent;
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicBoolean;

public class NewSendHelper extends SendHelper {

    private AtomicBoolean postInputVideoStreamLock;
    private AtomicBoolean sendKeyFailed;
    private int sendVideoErrorCounter;

    public NewSendHelper(SendHelperListener sendHelperListener) {
        super(sendHelperListener);
        this.postInputVideoStreamLock = new AtomicBoolean();
        this.sendKeyFailed = new AtomicBoolean();
        this.sendVideoErrorCounter = 0;
    }

    @Override
    public synchronized void addFrame(ByteBuffer byteBuffer, int i, long j) {
        if (this.postInputVideoStreamLock.get()) {
            return;
        }
        if (i == 1 || !this.sendKeyFailed.get()) {
            this.postInputVideoStreamLock.set(true);
            int inputVideoStream = JniGS28181Agent.getInstance().inputVideoStream(byteBuffer, i, j);
            if (inputVideoStream == 10000) {
                this.sendVideoErrorCounter = 0;
                this.sendKeyFailed.set(false);
            } else if (i == 1) {
                this.sendKeyFailed.set(true);
                if (inputVideoStream != 10010) {
                    int i2 = this.sendVideoErrorCounter + 1;
                    this.sendVideoErrorCounter = i2;
                    if (i2 > 60) {
                        forceStop();
                    }
                }
            }
            this.postInputVideoStreamLock.set(false);
        }
    }
}
